// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*
 * Path.h
 *
 *  Created on: Jan 7, 2010
 *      Author: dhovemey
 */

#ifndef PATH_H_
#define PATH_H_

#include <vector>
#include <string>

class Path {
private:
	typedef std::vector<std::string> ComponentList;

	std::string m_filesystemRoot;
	bool m_isAbsolute;
	ComponentList m_componentList;

public:
	Path(const std::string &pathName);
	Path(const Path &base, const std::string &pathName);
	Path(const Path &other);
	~Path();

	Path& operator=(const Path &rhs);

	const std::string asString() const;
	void popLastComponent();

	bool isAbsolute() const { return m_isAbsolute; }
	bool isDirectory();
	bool isFile();
	void makeDirectory();

	static bool isSeparator(char c);
	static Path getCurrentDirectory();

private:
	void parse(const std::string &pathName);
	void canonicalize();
};

#endif /* PATH_H_ */
